package com.dragondig.tetris;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class PlayActivity extends Activity {
	public static final int NEW_ID = Menu.FIRST;
	public static final int SCORE_ID = Menu.FIRST + 1;
	public static final int ABOUT_ID = Menu.FIRST + 2;
	public static final int BACK_ID = Menu.FIRST + 3;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.play);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
    	super.onCreateOptionsMenu(menu);
    	menu.add(0,NEW_ID,0,"NewGame");
    	menu.add(0,SCORE_ID,1,"Score");
    	menu.add(0,ABOUT_ID,2,"About...");
    	menu.add(0,BACK_ID,3,"Back");
    	return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item){
    	switch(item.getItemId()){
    		case NEW_ID:
    			PlayView pv = (PlayView)findViewById(R.id.playView);
    			pv.init();
    			break;
    		case SCORE_ID:
    			Intent score_intent = new Intent();
    			score_intent.setClass(PlayActivity.this, ScoreActivity.class);
    			startActivity(score_intent);
    			break;
    		case ABOUT_ID:
    			openAboutDialog();
    			break;
    		case BACK_ID:
    			finish();
    	}
    	return super.onOptionsItemSelected(item);
    }
    
    private void openAboutDialog(){
    	new AlertDialog.Builder(this)
    	.setTitle("About")
    	.setPositiveButton("OK", new OnClickListener(){
    		public void onClick(DialogInterface df,int whichButton){}
    		})
    	.setMessage(R.string.about)
    	.show();
    }
}
